package cn.sciento.farm.devicemanager.service.impl;

import cn.sciento.farm.devicemanager.dao.entity.AlarmLogSendResult;
import cn.sciento.farm.devicemanager.dao.entity.TenantSmsResidual;
import cn.sciento.farm.devicemanager.dao.mapper.AlarmLogSendResultMapper;
import cn.sciento.farm.devicemanager.dao.mapper.TenantSmsResidualMapper;
import cn.sciento.farm.devicemanager.service.AlarmLogSendResultService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author walton
 * @description
 * @date 2020/11/24 11:29
 */
@Service
public class AlarmLogSendResultServiceImpl implements AlarmLogSendResultService {

    @Autowired
    private AlarmLogSendResultMapper alarmLogSendResultMapper;

    @Override
    public int create(AlarmLogSendResult sendResult) {
        return alarmLogSendResultMapper.insert(sendResult);
    }

    @Override
    public IPage<AlarmLogSendResult> getAlarmLogSendResult(Long startTime, Long endTime, Integer areaId, Integer landId) {
        QueryWrapper<AlarmLogSendResult> queryWrapper = new QueryWrapper<>();
        if (startTime != 0 || endTime != 0) {
            queryWrapper.gt("send_time", startTime);
            queryWrapper.lt("send_time", endTime);
        }
        if (areaId != 0) {
            queryWrapper.eq("area_id", areaId);
        }
        if (landId != 0) {
            queryWrapper.eq("land_id", landId);
        }
        return alarmLogSendResultMapper.selectPage(new Page<>(1,10),queryWrapper);
    }

    @Override
    public int batchDeleteLogBysendTime(long sendTime) {
        QueryWrapper<AlarmLogSendResult> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("send_time", sendTime);
        return alarmLogSendResultMapper.delete(queryWrapper);
    }
}
